﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class AnswerInChannelAuthenticationRequestsController : ControllerBase
    {

        private readonly IAnswerInChannelAuthenticationRequestAppService _app;
        public AnswerInChannelAuthenticationRequestsController(IAnswerInChannelAuthenticationRequestAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("answerInChannels/{answerInChannelId:Guid}/authenticationRequest")]
        public ActionResult<AnswerInChannelAuthenticationRequestDto> GetAuthenticationRequest([FromRoute] Guid answerInChannelId)
        {
            var answerInChannelAuthenticationRequestDto = _app.GetByAnswerInChannelId(answerInChannelId);
            return Ok(answerInChannelAuthenticationRequestDto);
        }

        [HttpPut]
        [Route("authenticationRequests/{id:Guid}")]
        public ActionResult<AnswerInChannelAuthenticationRequestDto> Put([FromRoute] Guid id, [FromBody] AnswerInChannelAuthenticationRequestUpdateDto dto)
        {
            AnswerInChannelAuthenticationRequestDto answerInChannelAuthenticationRequest = _app.Update(id, dto);
            return Ok(answerInChannelAuthenticationRequest);
        }

        [HttpPost]
        [Route("answerInChannels/{answerInChannelId:Guid}/authenticationRequest")]
        public ActionResult<AnswerInChannelAuthenticationRequestDto> Post([FromRoute] Guid answerInChannelId, [FromBody] AnswerInChannelAuthenticationRequestCreateDto dto)
        {
            AnswerInChannelAuthenticationRequestDto answerInChannelAuthenticationRequest = _app.Add(answerInChannelId, dto);
            return CreatedAtAction(nameof(Post), new { id = answerInChannelAuthenticationRequest.Id }, answerInChannelAuthenticationRequest);
        }

        [HttpDelete]
        [Route("authenticationRequests/{id:Guid}")]
        public ActionResult Delete([FromRoute]Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
